package bar.dark.lee.manager;

import bar.dark.lee.R;
import bar.dark.lee.SuperTabActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.manager.card.CheckCardActivity;
import bar.dark.lee.manager.card.CreditCardActivity;
import bar.dark.lee.manager.money.BankMoneyActivitiy;
import bar.dark.lee.manager.money.RealMoneyActivity;
import bar.dark.lee.setting.SettingActivity;
import bar.dark.lee.setting.TipInfoActivity;
import bar.dark.lee.setting.TipsActivity;
import android.app.LocalActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.LinearLayout.LayoutParams;

public class ManagerTabActivity extends SuperTabActivity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.tab_activity);
		setTitle("자산관리");
		
		TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
		
		LocalActivityManager manager = getLocalActivityManager();
		tabHost.setup(manager);
		
		Intent gIntent = getIntent();
		
		int moneyFlag = gIntent.getIntExtra(SettingActivity.MONEY_FLAG, 0);
		
		Intent intent1 = new Intent(this, RealMoneyActivity.class);
		
		Intent intent2 = new Intent(this, BankMoneyActivitiy.class);
		
		Intent intent3 = new Intent(this, CheckCardActivity.class);
		
		Intent intent4 = new Intent(this, CreditCardActivity.class);
		
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				0, LayoutParams.FILL_PARENT);
		params.weight = 1;
		
		tabHost.addTab(tabHost.newTabSpec("현금")
				.setIndicator(BDUtil.getTextView(this, "현금"))
				.setContent(intent1));
		tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(0).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("통장")
				.setIndicator(BDUtil.getTextView(this, "통장"))
				.setContent(intent2));
		tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(1).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("체크카드")
				.setIndicator(BDUtil.getTextView(this, "체크카드"))
				.setContent(intent3));
		tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(2).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("신용카드")
				.setIndicator(BDUtil.getTextView(this, "신용카드"))
				.setContent(intent4));
		tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.btn_set_tab);
		tabHost.getTabWidget().getChildAt(3).setLayoutParams(params);
		
		tabHost.addTab(tabHost.newTabSpec("")
				.setIndicator(new LinearLayout(this))
				.setContent(new Intent()));
		tabHost.getTabWidget().getChildAt(4).setVisibility(View.GONE);
		tabHost.getTabWidget().getChildAt(4).setLayoutParams(params);
		
//		tabHost.getTabWidget().getChildAt(0).setPadding(0, 10, 0, 10);
//		tabHost.getTabWidget().getChildAt(1).setPadding(0, 10, 0, 10);
		
		tabHost.setCurrentTab(getMoneyFlag(moneyFlag));
	}
	
	private int getMoneyFlag(int flag)
	{
		if (flag == SettingActivity.REAL_MONEY)
		{
			return 0;
		}
		else if (flag == SettingActivity.BANK_MONEY)
		{
			return 1;
		}
		
		return 0;
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(this, TipInfoActivity.class);
		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_MANAGER);
		startActivity(intent);
	}
}
